package com.eian.boot.module.system.log.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.eian.boot.common.constants.PermissionConstants;
import com.eian.boot.common.core.model.CommonResult;
import com.eian.boot.module.system.log.model.dto.OperationLogQueryRequest;
import com.eian.boot.module.system.log.model.vo.OperationLogDetailVO;
import com.eian.boot.module.system.log.model.vo.OperationLogVO;
import com.eian.boot.module.system.log.service.SysOperationLogService;
import com.eian.boot.mybatis.core.page.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 操作日志控制器
 *
 * @author alex.meng
 */
@Tag(name = "操作日志")
@RestController
@RequestMapping("/system/log/operation")
@AllArgsConstructor
public class OperationLogController {

    private final SysOperationLogService operationLogService;

    @Operation(summary = "分页查询操作日志")
    @SaCheckPermission(PermissionConstants.OperationLog.LIST)
    @GetMapping("/list")
    public CommonResult<PageResult<OperationLogVO>> list(@Valid OperationLogQueryRequest request) {
        return CommonResult.ok(operationLogService.queryOperationLogs(request));
    }

    @Operation(summary = "获取日志详情")
    @SaCheckPermission(PermissionConstants.OperationLog.QUERY)
    @GetMapping("/{id}")
    public CommonResult<OperationLogDetailVO> getDetail(@Parameter(description = "日志ID") @PathVariable Long id) {
        return CommonResult.ok(operationLogService.getOperationLogDetail(id));
    }

    @Operation(summary = "批量删除日志")
    @SaCheckPermission(PermissionConstants.OperationLog.DELETE)
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody List<Long> ids) {
        operationLogService.deleteOperationLogs(ids);
        return CommonResult.ok("操作日志删除成功");
    }
}


